package com.tbit.uqbike.service.business.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.business.CalibrateUtils;
import com.tbit.uqbike.object.pojo.MainCar;
import com.tbit.uqbike.object.pojo.vo.MainCarPageReqVO;
import com.tbit.common.entity.view.PageResult;
import com.tbit.uqbike.service.base.CalibrateService;
import com.tbit.uqbike.service.business.MainCarService;
import com.tbit.uqbike.webmanager.dao.core.MainCarDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LMY
 * @create 2021-04-08 10:43
 * 运维车辆
 */
@Service("mainCarService")
public class MainCarServiceImpl implements MainCarService {

    @Autowired
    private MainCarDao mainCarDao;
    @Autowired
    private CalibrateService calibrateService;

    @Override
    public MainCar getByMachineNO(String machineNO) {
        return mainCarDao.getByMachineNO(machineNO);
    }

    @Override
    public MainCar getByMainCarId(Integer mainCarId) {
        return mainCarDao.getByMainCarId(mainCarId);
    }

    @Override
    public MainCar getByMainCarNO(String mainCarNO) {
        return mainCarDao.getByMainCarNO(mainCarNO);
    }

    @Override
    public void insert(MainCar mainCar) {
        mainCarDao.insert(mainCar);
    }

    @Override
    public void update(MainCar mainCar) {
        mainCarDao.update(mainCar);
    }

    @Override
    public void del(Integer mainCarId) {
        mainCarDao.del(mainCarId);
    }

    @Override
    public List<MainCar> getByAccountId(Integer accountId) {
        return mainCarDao.getByAccountId(accountId);
    }

    @Override
    @SuppressWarnings("resource")
    public PageResult<MainCar> getPage(MainCarPageReqVO reqVO) {
        PageInfo<MainCar> page = PageHelper.startPage(reqVO.getPageNO(), reqVO.getRowCount())
                .doSelectPageInfo(() -> mainCarDao.selectList(reqVO));
        CalibrateUtils.calibrateObjects(calibrateService, page.getList(), reqVO.getMapType());
        return PageResult.convertPage(page);
    }

    @Override
    public List<String> getNOByAccountId(Integer accountId) {
        return mainCarDao.getNOByAccountId(accountId);
    }

    @Override
    public List<Integer> getByCarIds(Integer accountId) {
        return mainCarDao.getByCarIds(accountId);
    }

    @Override
    public void updateBatch(List<MainCar> mainCars) {
        mainCarDao.updateBatch(mainCars);
    }

    @Override
    public List<String> getAllMachineNO() {
        return mainCarDao.getAllMachineNO();
    }
}
